#include "VertexFormats.fx"

struct VSOut
{
	float4 pos : POSITION;
	float2 uv : TEXCOORD0;
	float4 color : COLOR;
};

texture tex : SPRITE_TEXTURE;

sampler tex_sampler =
sampler_state
{
    Texture = <tex>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
	AddressU = CLAMP;
	AddressV = CLAMP;
};

VSOut VS_SpriteBatch(VertexPosUVColor input)
{
	VSOut output;
	output.pos = float4(input.pos, 1);
	output.uv = input.uv;
	output.color = input.color;
	return output;
}

float4 PS_SpriteBatch(VSOut input) : COLOR
{
    return tex2D(tex_sampler, input.uv) * input.color;
}

float4 PS_TiltedSpriteBatch(VSOut input) : COLOR
{
	float2 uv = float2(1 - input.uv.y, input.uv.x);
	return tex2D(tex_sampler, uv) * input.color;
}

// Normal blending
technique t0
{
	pass p0
	{
		VertexShader = compile vs_2_0 VS_SpriteBatch();
		PixelShader = compile ps_2_0 PS_SpriteBatch();
		
		AlphaBlendEnable = true;
		SrcBlend = srcAlpha;
		DestBlend = invSrcAlpha;
	}
}

// Additive blending
technique t1
{
	pass p0
	{
		VertexShader = compile vs_2_0 VS_SpriteBatch();
		PixelShader = compile ps_2_0 PS_SpriteBatch();

		AlphaBlendEnable = true;
		SrcBlend = srcAlpha;
		DestBlend = one;
	}
}

// Tilted
technique t3
{
	pass p0
	{
		VertexShader = compile vs_2_0 VS_SpriteBatch();
		PixelShader = compile ps_2_0 PS_TiltedSpriteBatch();

		AlphaBlendEnable = true;
		SrcBlend = srcAlpha;
		DestBlend = invSrcAlpha;
	}	
}

